from fastapi import APIRouter

from app.database.postgre import SessionDep
from app.models.common import CardIdParams, CardIdJSON, AppIdJSON, AppIdParams
from app.models.cards import (AppCardListParams, CreateCardJSON, UpdateCardJSON, FreezeCardJSON,
                              BatchDeleteAppCardsJSON, IncreaseCardsHourJSON)
from app.services import accounts, cards

router = APIRouter(
    prefix='/api/v1/cards',
    tags=['backend', 'cards']
)


@router.get('/list')
async def cards_list(
        account: accounts.LoggedInAccount,
        query_params: AppCardListParams,
        session: SessionDep):
    response = await cards.get_app_cards_list(account, query_params, session)
    return response


@router.post('/create')
async def create_cards(account: accounts.LoggedInAccount, json_data: CreateCardJSON, session: SessionDep):
    response = await cards.create_cards(account, json_data, session)
    return response


@router.post('/delete')
async def delete_card(account: accounts.LoggedInAccount, json_data: CardIdJSON, session: SessionDep):
    response = await cards.delete_card_by_id(account, json_data, session)
    return response


@router.post('/batch_delete')
async def batch_delete_cards(account: accounts.LoggedInAccount, json_data: BatchDeleteAppCardsJSON,
                             session: SessionDep):
    response = await cards.delete_card_by_ids(account, json_data, session)
    return response


@router.post('/clear')
async def clear_app_cards(account: accounts.LoggedInAccount, json_data: AppIdJSON, session: SessionDep):
    response = await cards.clear_all_app_cards(account, json_data, session)
    return response


@router.post('/cleanup')
async def cleanup_cards(account: accounts.LoggedInAccount, json_data: AppIdJSON, session: SessionDep):
    response = await cards.cleanup_expired_cards(account, json_data, session)
    return response


@router.get('/info')
async def card_info(account: accounts.LoggedInAccount, query_params: CardIdParams, session: SessionDep):
    response = await cards.get_card_info(account, query_params, session)
    return response


@router.post('/update')
async def update_card(account: accounts.LoggedInAccount, json_data: UpdateCardJSON, session: SessionDep):
    response = await cards.update_card_by_id(account, json_data, session)
    return response


@router.post('/freeze')
async def freeze_card(account: accounts.LoggedInAccount, json_data: FreezeCardJSON, session: SessionDep):
    response = await cards.freeze_card_by_id(account, json_data, session)
    return response


@router.get('/statistics')
async def statistics(account: accounts.LoggedInAccount, query_params: AppIdParams, session: SessionDep):
    response = await cards.get_card_statistics(account, query_params, session)
    return response


@router.get('/devices')
async def card_devices(account: accounts.LoggedInAccount, query_params: CardIdParams, session: SessionDep):
    response = await cards.get_card_devices(account, query_params, session)
    return response


@router.post('/hour/increase')
async def increase_hour(account: accounts.LoggedInAccount, json_data: IncreaseCardsHourJSON, session: SessionDep):
    response = await cards.increase_cards_hour(account, json_data, session)
    return response
